package com.yuyou.tas.feedback.api;

import com.yuyou.tas.feedback.service.IFeedbackCommentService;
import com.yuyou.tas.service.api.feedback.dto.FeedbackCommentDTO;
import com.yuyou.tas.service.api.feedback.entity.FeedbackComment;
import com.yuyou.tas.service.api.feedback.service.FeedbackCommentAPI;
import com.yuyou.tas.service.api.feedback.vo.resp.UnReadSimpleVo;
import com.yuyou.tas.util.enums.feedback.FeedbackCommentEnums;
import com.yuyou.tas.util.tool.DateUtil;
import com.yuyou.tas.util.tool.Sequence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class FeedbackCommentAPIImpl implements FeedbackCommentAPI{

    @Autowired
    private IFeedbackCommentService feedbackCommentService;

    @Override
    public Long saveFeedbackComment(@RequestParam("feedbackId")Long feedbackId , @RequestParam("content")String content ,
            @RequestParam("organId")Long organId, @RequestParam("userId")Long userId,
            @RequestParam("type")Integer type) {
        FeedbackComment feedbackComment = new FeedbackComment();
        feedbackComment.setId(Sequence.getSequence().nextId());
        feedbackComment.setAuthOrganizationId(organId);
        feedbackComment.setFeedbackId(feedbackId);
        feedbackComment.setContent(content);
        feedbackComment.setUserId(userId);
        feedbackComment.setType(type == null ? FeedbackCommentEnums.userType.stu.getValue():type);
        feedbackComment.setCreateTime(DateUtil.now());
        feedbackCommentService.insert(feedbackComment);

        return feedbackComment.getId();
    }

    @Override
    public List<FeedbackCommentDTO> feedbackCommentList(@RequestParam("feedbackId")Long feedbackId) {
    	return feedbackCommentService.findFeedbackCommentList(feedbackId);
	}

    @Override
    public Integer getTeacherUnReadCount(@RequestParam("userId")Long userId) {
        return feedbackCommentService.getTeacherUnReadCount(userId);
    }

    @Override
    public List<UnReadSimpleVo> getTeacherClassUnReadCount(@RequestParam("userId")Long userId ,
                                                           @RequestParam("list")List<Long> list) {
        return feedbackCommentService.getTeacherClassUnReadCount(userId , list);
    }
}
